﻿$(document).ready(function() {
    $(window).scroll(function () {
      
        if (!!$('#advertise').offset()) { // make sure ".sticky" element exists

            var stickyTop = $('#advertise').offset().top; // returns number 

            $(window).scroll(function () { // scroll event

                var windowTop = $(window).scrollTop(); // returns number 

                if (stickyTop < windowTop) {
                    $('#advertise').css({ position: 'fixed', top: 0 });
                }
                else {
                    $('#advertise').css('position', 'static');
                }

            });

        }
        
        //var scrollTop = $(this).scrollTop();
        //var top = $('#advertise').position().top;
        ////var top2 = $('#video').position().top;
        //if ((top - scrollTop) <= -100) {
        //    $('#advertise').addClass('fixcel');
        //}
        ////var down = $('#video').position().bottom;
        //var heights = $(document).height();
       
        //if (scrollTop <= heights/100) {
        //    $('#advertise').removeClass('fixcel');
        //}
    });
    
    //$('html, body').animate({
    //    scrollTop: $("#commic").offset().top
    //}, 1000);
});

function Getytinfo(id) {
    $.getJSON('http://gdata.youtube.com/feeds/api/videos/' + id + '?v=2&alt=jsonc', function (data, status, xhr) {
        $('#videotitle').html(data.data.title);
        //$('#videodecription').html(data.data.duration);
        //$('#videoview').html(data.data.viewCount + '-' + data.data.rating);
        var h = parseInt(data.data.duration / 3600) > 0 ? parseInt(data.data.duration / 3600) > 9 ? parseInt(data.data.duration / 3600) : '0' + parseInt(data.data.duration / 3600) : '00';
        var m = parseInt(data.data.duration / 60) > 0 ? parseInt(data.data.duration / 60) > 9 ? parseInt(data.data.duration / 60) : '0' + parseInt(data.data.duration / 60) : '00';
        var s = parseInt(data.data.duration % 60);
        $('#time1').html(h + ':' + m + ':' + s);
        $('#img1').attr("src", data.data.thumbnail.sqDefault);
        // alert(parseInt(data.data.duration / 60));
    });
}
